package com.tvunetworks.center.device.util;

import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.device.constant.DeviceConstant;

/**
 * @program: tvucc-device
 * @description: 封装R返回值工具类
 * @author lebronchen
 * @create: 2019-03-17 11:01
 **/
public class ReceiverResultUtil {
    /**
     *
     * @param result result
     * @return Result
     */
    public static Result<String> startLiveResult(Result<String> result){
        if (!result.assertSuccess()) {
            return result;
        }
        String resultData = result.getResult();
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StartLive.UNKNOWN)) {
            return ResultUtil.error("81100106", "Receiver error: Unknow");
        }
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StartLive.PEERNOTFOUND)) {
            return ResultUtil.error("81100107", "Receiver error: PeerNotFound");
        }
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StartLive.PEETINLIVEWITHOTHER)) {
            return ResultUtil.error("81100108", "Receiver error: PeerInLiveWithOther");
        }
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StartLive.PEERINCORRECTSTATUS)) {
            return ResultUtil.error("81100109", "Receiver error: PeerIncorrectStatus");
        }
        return result;
    }

    /**
     *
     * @param result result
     * @return Result
     */
    public static Result<String> stopLiveResult(Result<String> result){
        if (!result.assertSuccess()) {
            return result;
        }
        String resultData = result.getResult();
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StopLive.UNKNOWN)) {
            return ResultUtil.error("81100204", "Receiver error: Unknow");
        }
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StopLive.PEERNOTFOUND)) {
            return ResultUtil.error("81100205", "Receiver error: PeerNotFound");
        }
        if (resultData.contains(DeviceConstant.ReceiverCommandResult.StopLive.GIVENPEERNOTSELECTED)) {
            return ResultUtil.error("81100206", "Receiver error: GivenPeerNotSelected");
        }

        return result;
    }
}
